﻿using Castle.DynamicProxy;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TViewCore;

namespace TViewCoreTest
{
    public class Program
    {
        public class Model
        {
            public virtual int Value { get; set; }
        }

        static void Main(string[] args)
        {
            var model = new Model { Value = 30 };
            var pg = new ProxyGenerator();
            var pi = new PropertyInterceptor(model);

            model = (Model)pg.CreateClassProxy(model.GetType(), new IInterceptor[] { pi });
            var action = new Action<object>(m =>
            {
                Console.WriteLine("Value值发生变化:"+((Model)m).Value);
            });
            //添加到监听
            new Watcher(model, "Value", action);
            //初始化数据（将实体数据赋给控件属性）
            action(model);

            model.Value = 133;
            model.Value = 3445;
            model.Value = 56756;
            //这个值与前一个相等，则不刷新
            model.Value = 56756;
            model.Value = 5656;
            Console.ReadLine();
        }
    }
}
